﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JqueryMvcProject.App_Start.MyDefinedMvcCoreMethod
{
    /// <summary>
    /// 我自定义的action过滤器 
    /// 例子放在 NotCommonlyUsedMethodController
    /// </summary>
    [AttributeUsage(AttributeTargets.All,AllowMultiple=true)]//默认的 可以不写控制作用的地方以及是否可以作用于多个地方
    public class MyDefinedActionAttribute : ActionFilterAttribute
    {
        /// <summary>
        /// 例子 任意字段
        /// </summary>
        public string SomeFiled { get; set; }
        /// <summary>
        /// Action执行之前执行
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            filterContext.HttpContext.Response.Write("我自定义的action执行前过滤器" + SomeFiled+"<br/>");
        }
        /// <summary>
        /// Action执行后前执行
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            filterContext.HttpContext.Response.Write("我自定义的action执行完成后过滤器" + SomeFiled + "<br/>");
        }
        /// <summary>
        /// 视图执行后执行
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            base.OnResultExecuted(filterContext);
            filterContext.HttpContext.Response.Write("我自定义的视图执行完成后过滤器" + "<br/>");
        }
        /// <summary>
        /// 视图执行前执行
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);
            filterContext.HttpContext.Response.Write("我自定义的视图执行前过滤器" + SomeFiled + "<br/>");
        }
    }
}